package com.wanma;

import java.util.Comparator;
import java.util.function.BinaryOperator;

/**
 * 测试BinaryOperator
 * 
 * @author Administrator
 *
 */
public class TestDemo {

	public static void main(String[] args) {
		BinaryOperator<Integer> add = (o, n) -> n;
		// apply方法用于接收参数，并返回BinaryOperator中的Integer类型
		System.out.println(add.apply(3, 4));
		BinaryOperator<String> addStr = (n1, n2) -> n1 + "===" + n2;
		// apply方法用于接收参数，并返回BinaryOperator中的String类型
		System.out.println(addStr.apply("3", "4"));
		// 最小值  (a, b) -> comparator.compare(a, b) <= 0 ? a : b    a>b= 1 a=b 0 a<b -1  
		//
		BinaryOperator<Integer> bi = BinaryOperator.minBy(Comparator.naturalOrder());
		System.out.println(bi.apply(2, 3));
		// 最大值 (a, b) -> comparator.compare(a, b) >= 0 ? a : b  
		BinaryOperator<Integer> ai = BinaryOperator.maxBy(Comparator.naturalOrder());
		System.out.println(ai.apply(2, 3));
		
		
	}
}
